package com.InsideGamer.SuperJailBreak;

//import java.io.FileInputStream;
//import java.io.FileOutputStream;
//import java.io.ObjectInputStream;
//import java.io.ObjectOutputStream;
//import java.util.HashMap;

//import org.bukkit.Location;
//import org.bukkit.entity.Player;

class Pair
{
	public int x;
	public int y;
	
	public Pair(int newx, int newy)
	{
		x = newx;
		y = newy;
	}
}

public class ProtectionClass
{
	/*private JailBreak plugin;
	private String protectionFile = null;
	
	private HashMap<String, Object> protectedAreas = new HashMap<String, Object>();
	private HashMap<String, Pair> corner1 = new HashMap<String, Pair>();
	private HashMap<String, Pair> corner2 = new HashMap<String, Pair>();
	
	
	public ProtectionClass ( JailBreak pluginInstance, String protectionFileArg )
	{
		plugin = pluginInstance;
		protectionFile = protectionFileArg;
	}
	
	public void LoadAllProtection ( )
	{
		try {
			protectedAreas = LoadProtections ( protectionFile );
			plugin.getServer().broadcastMessage(protectedAreas.toString());
		} catch (Exception e) {
			e.printStackTrace();
		}
	}
	
	public void AddLocation ( String player, Pair p1, Pair p2 )
	{
		corner1.put(player, p1);
		corner2.put(player, p2);
	}
	
	public boolean IsInLocation ( Player player )
	{
		for ( Object obj : protectedAreas.values() )
		{
			plugin.BroadcastMessage(obj.toString());
		}
		Location loc1 = new Location (player.getWorld(), -19.0, 0, -380.0 );
		Location loc2 = new Location (player.getWorld(), -14.0, 0, -365.0 );
		Location locP = player.getLocation();
		
		if ( locP.getX() >= loc1.getBlockX() && locP.getZ() >= loc1.getBlockZ() &&
			 locP.getX() <= loc2.getBlockX() && locP.getZ() <= loc2.getBlockZ() )
		{
			//plugin.getServer().broadcastMessage ( player.getName() + " is nu in een beschermd gebied!" );
		}
		
		return false;
	}
	
	public void SaveLocation ( String world, String player, String name )
	{
		HashMap<String, Object> protectedTemp = new HashMap<String, Object>();
		protectedTemp.put ( "loc1", corner1.get ( player ) );
		protectedTemp.put ( "loc2", corner2.get ( player ) );
		protectedTemp.put ( "owner", player );
		protectedTemp.put ( "canBluid", false );
		protectedTemp.put ( "pvp", false );
		protectedTemp.put ( "rent", false );
		protectedTemp.put ( "prizekk", 0.00 );
		protectedTemp.put ( "prizerent", 0.00 );
		protectedTemp.put ( "rentBy", false );
		
		corner1.remove ( player );
		corner2.remove ( player );
		
		HashMap<String, Object> protectedName = new HashMap<String, Object>();
		protectedName.put ( name, protectedTemp );
		
		protectedAreas.put ( world, protectedName );
		
		try {
			SaveProtections ( protectedAreas );
		} catch (Exception e) {
			e.printStackTrace();
		}
		
		plugin.BroadcastMessage("Area saved!");
	}
	
	public void SaveProtections ( HashMap<String, Object> obj ) throws Exception
	{
		ObjectOutputStream oos = new ObjectOutputStream(new FileOutputStream ( protectionFile ) );
		oos.writeObject(obj);
		oos.flush();
		oos.close();
	}
	
	@SuppressWarnings("unchecked")
	public HashMap<String, Object> LoadProtections ( String path ) throws Exception
	{
		ObjectInputStream ois = new ObjectInputStream(new FileInputStream(path));
		Object result = ois.readObject();
		ois.close();
		return (HashMap<String, Object>) result;
	}*/
}
